﻿using TechnicalIndicators.Points;
using Utils;

namespace StockAnalyst2.Plugins
{
	public class ExecutionResultStatistics : PropertyChangedNotifier
	{
		#region Attributes

		private int _totalOperations;
		private int _totalDays;
		private int _winOperations;
		private int _lossOperations;
		private decimal _totalResult;
		private decimal _maxWinOperation;
		private decimal _maxLossOperation;
		private decimal _averageOperation;
		private decimal _averageGrossOperation;
		private decimal _totalWin;
		private decimal _averageWin;
		private decimal _totalLoss;
		private decimal _averageLoss;
		private decimal _maxWin;
		private decimal _maxLoss;
		private decimal _maxAmountRequired;
		private decimal _profit;
		private decimal _dailyProfit;
		private decimal _worstResult;
		private decimal _bestResult;
		private decimal _worstResultPercentage;
		private decimal _bestResultPercentage;
		private decimal _winOperationsPercentage;
		private decimal _lossOperationsPercentage;
		private DateRange _worstResultPeriod;
		private DateRange _bestResultPeriod;

		#endregion

		#region Properties

		public int TotalOperations
		{
			get
			{
				return _totalOperations;
			}
			internal set
			{
				if (_totalOperations != value)
				{
					_totalOperations = value; 
					base.OnPropertyChanged("TotalOperations");
				}
			}
		}

		public int TotalDays
		{
			get
			{
				return _totalDays;
			}
			internal set
			{
				if (_totalDays != value)
				{
					_totalDays = value;
					base.OnPropertyChanged("TotalDays");
				}
			}
		}


		public int WinOperations
		{
			get
			{
				return _winOperations;
			}
			internal set
			{
				if (_winOperations != value)
				{
					_winOperations = value;
					base.OnPropertyChanged("WinOperations");
				}
			}
		}

		public int LossOperations
		{
			get
			{
				return _lossOperations;
			}
			internal set
			{
				if (_lossOperations != value)
				{
					_lossOperations = value;
					base.OnPropertyChanged("LossOperations");
				}
			}
		}

		public decimal TotalResult
		{
			get
			{
				return _totalResult;
			}
			internal set
			{
				if (_totalResult != value)
				{
					_totalResult = value;
					base.OnPropertyChanged("TotalResult");
				}
			}
		}

		public decimal MaxWinOperation
		{
			get
			{
				return _maxWinOperation;
			}
			internal set
			{
				if (_maxWinOperation != value)
				{
					_maxWinOperation = value;
					base.OnPropertyChanged("MaxWinOperation");
				}
			}
		}

		public decimal MaxLossOperation
		{
			get
			{
				return _maxLossOperation;
			}
			internal set
			{
				if (_maxLossOperation != value)
				{
					_maxLossOperation = value;
					base.OnPropertyChanged("MaxLossOperation");
				}
			}
		}

		public decimal AverageOperation
		{
			get
			{
				return _averageOperation;
			}
			internal set
			{
				if (_averageOperation != value)
				{
					_averageOperation = value;
					base.OnPropertyChanged("AverageOperation");
				}
			}
		}

		public decimal AverageGrossOperation
		{
			get
			{
				return _averageGrossOperation;
			}
			internal set
			{
				if (_averageGrossOperation != value)
				{
					_averageGrossOperation = value;
					base.OnPropertyChanged("AverageGrossOperation");
				}
			}
		}

		public decimal TotalWin
		{
			get
			{
				return _totalWin;
			}
			internal set
			{
				if (_totalWin != value)
				{
					_totalWin = value;
					base.OnPropertyChanged("TotalWin");
				}
			}
		}

		public decimal AverageWin
		{
			get
			{
				return _averageWin;
			}
			internal set
			{
				if (_averageWin != value)
				{
					_averageWin = value;
					base.OnPropertyChanged("AverageWin");
				}
			}
		}

		public decimal TotalLoss
		{
			get
			{
				return _totalLoss;
			}
			internal set
			{
				if (_totalLoss != value)
				{
					_totalLoss = value;
					base.OnPropertyChanged("TotalLoss");
				}
			}
		}

		public decimal AverageLoss
		{
			get
			{
				return _averageLoss;
			}
			internal set
			{
				if (_averageLoss != value)
				{
					_averageLoss = value;
					base.OnPropertyChanged("AverageLoss");
				}
			}
		}

		public decimal MaxWin
		{
			get
			{
				return _maxWin;
			}
			internal set
			{
				if (_maxWin != value)
				{
					_maxWin = value;
					base.OnPropertyChanged("MaxWin");
				}
			}
		}

		public decimal MaxLoss
		{
			get
			{
				return _maxLoss;
			}
			internal set
			{
				if (_maxLoss != value)
				{
					_maxLoss = value;
					base.OnPropertyChanged("MaxLoss");
				}
			}
		}

		public decimal MaxAmountRequired
		{
			get
			{
				return _maxAmountRequired;
			}
			internal set
			{
				if (_maxAmountRequired != value)
				{
					_maxAmountRequired = value;
					base.OnPropertyChanged("MaxAmountRequired");
				}
			}
		}

		public decimal Profit
		{
			get
			{
				return _profit;
			}
			internal set
			{
				if (_profit != value)
				{
					_profit = value;
					base.OnPropertyChanged("Profit");
				}
			}
		}

		public decimal DailyProfit
		{
			get
			{
				return _dailyProfit;
			}
			internal set
			{
				if (_dailyProfit != value)
				{
					_dailyProfit = value;
					base.OnPropertyChanged("DailyProfit");
				}
			}
		}

		public decimal WorstResult
		{
			get
			{
				return _worstResult;
			}
			internal set
			{
				if (_worstResult != value)
				{
					_worstResult = value;
					base.OnPropertyChanged("WorstResult");
				}
			}
		}

		public decimal BestResult
		{
			get
			{
				return _bestResult;
			}
			internal set
			{
				if (_bestResult != value)
				{
					_bestResult = value;
					base.OnPropertyChanged("BestResult");
				}
			}
		}

		public decimal WorstResultPercentage
		{
			get
			{
				return _worstResultPercentage;
			}
			internal set
			{
				if (_worstResultPercentage != value)
				{
					_worstResultPercentage = value;
					base.OnPropertyChanged("WorstResultPercentage");
				}
			}
		}

		public decimal BestResultPercentage
		{
			get
			{
				return _bestResultPercentage;
			}
			internal set
			{
				if (_bestResultPercentage != value)
				{
					_bestResultPercentage = value;
					base.OnPropertyChanged("BestResultPercentage");
				}
			}
		}

		public decimal WinOperationsPercentage
		{
			get
			{
				return _winOperationsPercentage;
			}
			internal set
			{
				if (_winOperationsPercentage != value)
				{
					_winOperationsPercentage = value;
					base.OnPropertyChanged("WinOperationsPercentage");
				}
			}
		}

		public decimal LossOperationsPercentage
		{
			get
			{
				return _lossOperationsPercentage;
			}
			internal set
			{
				if (_lossOperationsPercentage != value)
				{
					_lossOperationsPercentage = value;
					base.OnPropertyChanged("LossOperationsPercentage");
				}
			}

		}
		public DateRange WorstResultPeriod
		{
			get
			{
				return _worstResultPeriod;
			}
			internal set
			{
				if (_worstResultPeriod != value)
				{
					_worstResultPeriod = value;
					base.OnPropertyChanged("WorstResultPeriod");
				}
			}
		}

		public DateRange BestResultPeriod
		{
			get
			{
				return _bestResultPeriod;
			}
			internal set
			{
				if (_bestResultPeriod != value)
				{
					_bestResultPeriod = value;
					base.OnPropertyChanged("BestResultPeriod");
				}
			}
		}


		public ObservableCollection2<DatedSeriePoint> AccumulatedOperationPartials { get; private set; }
		public ObservableCollection2<DatedSeriePoint> DailyPartials { get; private set; }
		public ObservableCollection2<DatedSeriePoint> AccumulatedDailyPartials { get; private set; }
		public ObservableCollection2<DatedSeriePoint> AmountsRequired { get; private set; }

		#endregion

		#region Public Methods

		public ExecutionResultStatistics()
		{
			this.AccumulatedOperationPartials = new ObservableCollection2<DatedSeriePoint>();
			this.DailyPartials = new ObservableCollection2<DatedSeriePoint>();
			this.AccumulatedDailyPartials = new ObservableCollection2<DatedSeriePoint>();
			this.AmountsRequired = new ObservableCollection2<DatedSeriePoint>();
		}

		public void Clear()
		{
			this.TotalOperations = 0;
			this.TotalDays = 0;
			this.WinOperations = 0;
			this.LossOperations = 0;
			this.TotalResult = 0;
			this.MaxWinOperation = 0;
			this.MaxLossOperation = 0;
			this.AverageOperation = 0;
			this.TotalWin = 0;
			this.AverageWin = 0;
			this.TotalLoss = 0;
			this.AverageLoss = 0;
			this.MaxWin = 0;
			this.MaxLoss = 0;
			this.MaxAmountRequired = 0;
			this.Profit = 0;
			this.WorstResult = 0;
			this.BestResult = 0;
			this.WorstResultPercentage = 0;
			this.BestResultPercentage = 0;
			this.LossOperationsPercentage = 0;
			this.WinOperationsPercentage = 0;

			this.BestResultPeriod = null;
			this.WorstResultPeriod = null;

			this.AccumulatedOperationPartials.Clear();
			this.DailyPartials.Clear();
			this.AccumulatedDailyPartials.Clear();
			this.AmountsRequired.Clear();
		}

		#endregion
	}
}
